package com.net.wanjian.networkhospitalmanager.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.adapter.base.RecyclerBaseAdapter;
import com.net.wanjian.networkhospitalmanager.bean.evaluate.SearchEventBasicInfoResult;
import com.net.wanjian.networkhospitalmanager.net.HttpUtil;
import com.net.wanjian.networkhospitalmanager.utils.PicassoUtil;
import com.net.wanjian.networkhospitalmanager.utils.SharedXmlUtil;
import com.net.wanjian.networkhospitalmanager.utils.URLDecoderUtil;
import com.net.wanjian.networkhospitalmanager.view.CircleImageView;
import com.zhy.autolayout.utils.AutoUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description:
 * Created by lidongcai on 17/7/20.
 * Email:  lidongcaiocc@163.com
 */

public class EvaluateDetailsTeacherGridAdapter extends RecyclerBaseAdapter<SearchEventBasicInfoResult.DataBean.BeEvaluatedUserInfoListBean, EvaluateDetailsTeacherGridAdapter.ViewHolder> {

    public EvaluateDetailsTeacherGridAdapter(Context context) {
        super(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_simple_evaluate_teacher_head_grid, parent, false);
        AutoUtils.auto(view);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, SearchEventBasicInfoResult.DataBean.BeEvaluatedUserInfoListBean item, int position) {
        holder.itemSimpleEvaluateTeacherHeadGridTv.setText(URLDecoderUtil.getDecoder(item.getUserTrueName()));
        PicassoUtil.loadImage(context,
                HttpUtil.getImageUrl(SharedXmlUtil.getInstance().getHospitalId(), URLDecoderUtil.getDecoder(item.getUserInfoID()), 2),
                R.mipmap.user, holder.itemSimpleEvaluateTeacherHeadGridIv);
        if (item.isSelect()){
           holder.itemSimpleEvaluateTeacherSelectGridIv.setVisibility(View.VISIBLE);
        }else {
            holder.itemSimpleEvaluateTeacherSelectGridIv.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_simple_evaluate_teacher_head_grid_iv)
        CircleImageView itemSimpleEvaluateTeacherHeadGridIv;
        @BindView(R.id.item_simple_evaluate_teacher_head_grid_tv)
        TextView itemSimpleEvaluateTeacherHeadGridTv;
        @BindView(R.id.item_simple_evaluate_teacher_select_grid_iv)
        ImageView itemSimpleEvaluateTeacherSelectGridIv;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
